using System;
using System.Runtime.Serialization;

namespace MiniStock.Entities.Common.Events
{
    [DataContract]
    public abstract class ResultEvent: EntityEventBase
    {
        [DataMember]
        public string EntityXml { get; set; }

        public EntityBase Entity
        {
            get { return EntityXml.ToEntityBase(); }
            set { EntityXml = value.ToXmlString(); }
        }

        public override bool IsConstructionMessage
        {
            get { return false; }
        }

        public override string GetEntityHash()
        {
            return Entity == null ? this.GetType().Name : Entity.GetEntityHash();
        }

        public override void ValidateFor(EntityBase entity, IEntityProvider provider)
        {
            throw new ApplicationException("ResultEvent event cannot be applied to entities");
        }

        public override void ApplyTo(EntityBase entity)
        {
            throw new ApplicationException("ResultEvent event cannot be applied to entities");
        }

        public override Type GetEntityType()
        {
            throw new ApplicationException("ResultEvent event cannot be applied to entities");
        }
    }
}
